//
//  IFToolBarViewController.m
//  IfengNews
//
//  Created by Ryan on 14-9-19.
//
//

#import "IFToolBarViewController.h"
#import "BlockUI.h"
#import "CLBaseViewController.h"
#import "INHtmlElementUtil.h"
#import "CLCollectModel.h"
#import "UIView+Utils.h"
#import "CLNavigationController.h"


@interface IFToolBarViewController ()


@property (nonatomic,strong)UIButton *showCommentButton;
@property (nonatomic,strong)UIButton *writeCommentButton;
@property (nonatomic,strong)UIButton *litCollectButton;
@property (nonatomic,strong)UIButton *fontButton;
@property (nonatomic,strong)UILabel *countLabel;
@property (nonatomic,unsafe_unretained)BOOL isPannelShow;
@property (nonatomic,strong)UIView *commentBg;
@property (nonatomic,strong)UIView *toolPannel;

@property (nonatomic,strong)NSMutableArray *fontSizeButtons;
@property (nonatomic,copy)void (^more)(BOOL ishow);
@property (nonatomic,copy)void (^fontblock)(int index);
@property (nonatomic,weak)UIButton *colloctButton;
@property (nonatomic,weak)UIButton *unlockButton;
@property (nonatomic,weak)UIButton *mycolloctButton;
@property (nonatomic,weak)UIButton *nightButton;
@property (nonatomic,weak)UIButton *imgButton;

@property (nonatomic,strong) NSString *collocId;
@property (nonatomic,strong) NSDictionary *data;
@property (nonatomic,strong) NSString *pty;

@property(nonatomic,strong)NSMutableArray *btnArr;// 所有的Btn集合
@property(nonatomic,strong)NSMutableArray *labArr;// 所有的label集合

@property (nonatomic,strong)UISlider *fontSlider;

@property (nonatomic, strong) UIScrollView *shareScrollView;
@property (nonatomic, strong) UIPageControl *pageControl;
@property (nonatomic, strong) UIButton *cancelBtn;
@property (nonatomic, strong) UIImageView *pageOne;
@property (nonatomic, strong) UIImageView *pageTwo;


@property (nonatomic,unsafe_unretained)BOOL isCollected;

@property (nonatomic, strong) UIImageView *fontPointImg;

@property (nonatomic, assign) BOOL isYinpin;

@end

static BOOL isShowToolBar;
@implementation IFToolBarViewController

- (instancetype)init{
    self=[super init];
    if(self){
        _btnArr = [[NSMutableArray alloc] initWithCapacity:9];
        _labArr = [[NSMutableArray alloc] initWithCapacity:9];
    }
    return self;
}


- (void)dealloc{
    NSLog(@"-------1");
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
        
    if(self.isSlider){
        [self buildSlider];
    }else{
        [self buildNomal];
    }
    
   

    
//    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isShowToolBar"]) {
//        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isShowToolBar"];
//        isShowToolBar = YES;
//    }
}

- (void)buildNomal{
    self.view.frame=CGRectMake(0, 0, GlobleWidth, 44.f);
    self.view.backgroundColor=[UIColor clearColor];
    UIView *bgView=[[UIView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:bgView];

    if(AtLeastIOS8){
        
        UIVisualEffectView *effectview=[[UIVisualEffectView alloc]
                                        initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
        
        effectview.frame=bgView.bounds;
        [bgView addSubview:effectview];
        
    }else{
        
        bgView.backgroundColor=RGB(236.f, 236.f, 236.f);
        bgView.alpha=0.99;
        
    }
    
//    CALayer *line=[CALayer layer];
//    
//    line.frame=CGRectMake(0, 0, GlobleWidth, 0.5f);
//    line.backgroundColor=RGB(150.f, 150.f, 150.f).CGColor;
//    [bgView.layer addSublayer:line];
    
    
    
    self.backButton=[UIButton buttonWithType:UIButtonTypeCustom];
    self.backButton.frame=CGRectMake(0.f, 4.f, 36.f, 36.f);
    self.backButton.contentEdgeInsets=UIEdgeInsetsMake(3.f, 3.f, 3.f, 3.f);
    [self.backButton setImage:[UIImage imageNamed:self.isSlider?@"slider_back.png":@"tb_back.png"]
                     forState:UIControlStateNormal];
    
    
    [self.view addSubview:self.backButton];
    __weak typeof(self) me=self;
    [self.backButton handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        [[me k_currentController].dispatchObj pop];
    }];

}

- (void)buildSlider{
    self.view.frame=CGRectMake(0, 0, GlobleWidth, 44.f);
    self.view.backgroundColor=[UIColor clearColor];
    UIView *bgView=[[UIView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:bgView];
    bgView.backgroundColor=[UIColor blackColor];;
    bgView.alpha=0.99;
    self.backButton=[UIButton buttonWithType:UIButtonTypeCustom];
    self.backButton.frame=CGRectMake(0.f, 4.f, 36.f, 36.f);
    self.backButton.contentEdgeInsets=UIEdgeInsetsMake(3.f, 3.f, 3.f, 3.f);
    [self.backButton setImage:[UIImage imageNamed:self.isSlider?@"slider_back.png":@"tb_back.png"]
                     forState:UIControlStateNormal];
    
    
    [self.view addSubview:self.backButton];
    __weak typeof(self) me=self;
    [self.backButton handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        [[me k_currentController].dispatchObj pop];
    }];

}



- (void)addButton:(IFActive_ButtomToolBarButtonType)buttonType{
    
    CGRect frame=CGRectMake(GlobleWidth-12.f-20.f, 12.f, 20.f, 20.f);
    int a=0;
    
    if(buttonType & IFActive_ButtomToolBarButtonTypeShare){
        self.shareButton=[UIButton buttonWithType:UIButtonTypeCustom];
       
        self.shareButton.frame=frame;
        [self.shareButton setImage:[UIImage imageNamed:self.isSlider?@"slider_share_icon.png":@"tb_share.png"] forState:UIControlStateNormal];
     
        [self.view addSubview:self.shareButton];
        frame.origin.x-=(20.f+(self.isSlider?20.f:20.f));
        a++;
    }
    
    if(buttonType & IFActive_ButtomToolBarButtonTypeCollect){
        self.litCollectButton=[UIButton buttonWithType:UIButtonTypeCustom];
        self.litCollectButton.frame=frame;
        [self.litCollectButton setImage:[UIImage imageNamed:(self.isSlider?@"slider_collect_icon.png":@"tb_collect.png")] forState:UIControlStateNormal];
        [self.view addSubview:self.litCollectButton];
        frame.origin.x-=(20.f+(self.isSlider?20.f:20.f));
        __weak typeof(self) me=self;
        [self.litCollectButton handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            if(_isStrNULL(me.collectId)) return ;
            if(me.isCollected ){
                [[CLCollectModel sharedInstance] deleteItemId:me.collectId block:^(BOOL success) {
                    me.isCollected=NO;
                }];
            }else{
                [[CLCollectModel sharedInstance] saveList:me.collectId block:^(BOOL success) {
                    if(success){
                        me.isCollected=YES;
                    }else{
                        [[CLGloble sharedInstance] showTieAlertMessage:@"提示" subMessage:@"收藏失败"];
                    }
                }];
            }
        }];
        a++;
    }
    
    if(buttonType & IFActive_ButtomToolBarButtonTypeDownloadImg){
        self.download=[UIButton buttonWithType:UIButtonTypeCustom];
        self.download.frame=frame;
        [self.download setImage:[UIImage imageNamed:@"slider_load_icon.png"] forState:UIControlStateNormal];
        [self.view addSubview:self.download];
        frame.origin.x-=(20.f+(self.isSlider?20.f:20.f));
        a++;
    }
    
    
    if(buttonType & IFActive_ButtomToolBarButtonTypeFont){
        self.fontButton=[UIButton buttonWithType:UIButtonTypeCustom];
        self.fontButton.frame=frame;
        [self.fontButton setImage:[UIImage imageNamed:@"tb_font.png"] forState:UIControlStateNormal];
        [self.view addSubview:self.fontButton];
        frame.origin.x-=(20.f+(self.isSlider?20.f:20.f));
        __weak typeof(self) me=self;
        [self.fontButton handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
//            [me showMorePannel:0];
            [me showFontPannel:0 withIsYinpin:NO];
        }];
        a++;
    }
    
    if(buttonType & IFActive_ButtomToolBarButtonTypeShowComment){
        self.showCommentButton=[UIButton buttonWithType:UIButtonTypeCustom];
        
        CGRect aframe=frame;
        aframe.size.width=22.f;
        
        self.showCommentButton.hidden=YES;
        
        self.showCommentButton.frame=aframe;
        
        self.countLabel=[[UILabel alloc] init];
        self.countLabel.frame=CGRectMake(0.f, 3.f, 22.f, 15.f);
        
        self.countLabel.textAlignment=NSTextAlignmentCenter;
        // self.countLabel.font=[UIFont systemFontOfSize:9];
        self.countLabel.font=[UIFont fontWithName:@"Avenir-Medium" size:9.f];
        [self.showCommentButton addSubview:self.countLabel];
    
        [self resizeComment];
        
        self.countLabel.textColor=RGB(0xff, 0x30, 0x3b);
        
        [self.view addSubview:self.showCommentButton];
        // frame.origin.x-=(22.f+29.f)-10;
        a++;
        
    }
    
    if(buttonType & IFActive_ButtomToolBarButtonTypeWriteComment){
        self.writeCommentButton=[UIButton buttonWithType:UIButtonTypeCustom];
        self.writeCommentButton.frame=frame;
        [self.writeCommentButton setImage:[UIImage imageNamed:self.isSlider?@"slider_write_background.png":@"tb_write_background.png"] forState:UIControlStateNormal];
        [self.view addSubview:self.writeCommentButton];

        frame.size.width = 100;//self.showCommentButton.left-40-20;
        frame.size.height = 28;
        frame.origin.y = 8;
        frame.origin.x=40;
        
        UIImageView *iconImg = [[UIImageView alloc]initWithFrame:CGRectMake(6, 6, 18, 18)];
        [iconImg setImage:[UIImage imageNamed:self.isSlider?@"tb_wComment.png":@"slider_write_comment_icon.png"]];
        [self.writeCommentButton addSubview:iconImg];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(iconImg.frame.origin.x+18+8, iconImg.frame.origin.y+2, 70, 14)];
        label.text = @"我来说两句";
        label.textAlignment = NSTextAlignmentLeft;
        label.font = [UIFont systemFontOfSize:12.f];
        label.textColor = RGB(0xc9, 0xc9, 0xc9);
        [self.writeCommentButton addSubview:label];
        
        self.writeCommentButton.frame=frame;
        if(a==3){
            self.writeCommentButton.width=142.f;
        }else
        if(a<3){
            self.writeCommentButton.width=172.f;
        }
    }
    
}

- (void)tapMark{
    //音频
    if (_isYinpin) {
        
        [self.toolPannel removeFromSuperview];
        self.toolPannel=nil;
        [self.markView removeFromSuperview];
        self.markView=nil;
        
        self.isPannelShow = NO;
        self.backButton.hidden = NO;
        self.fontButton.hidden = NO;
        CGRect frame = self.writeCommentButton.frame;
        frame.size.width = 100;
        frame.size.height = 28;
        frame.origin.y = 8;
        frame.origin.x=40;
        self.writeCommentButton.frame = frame;
        
        
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"showYinpinTool" object:nil];
        
    }else
        [self showMorePannel:0];
}

- (void)showFontPannel:(int)setting withIsYinpin:(BOOL)isYinpin {
    _isYinpin = isYinpin;
    if(self.isPannelShow){
        self.fontButton.enabled=NO;
        
        
        [UIView animateWithDuration:0.15f
                         animations:^{
                             CGRect frame=self.view.frame;
                             frame.origin.y=GlobleHeight-44.f;//170.f;
                             frame.size.height=44.f;
                             self.view.frame=frame;
                             self.markView.alpha=0;
                         }
                         completion:^(BOOL finished) {
                             
                             [self.toolPannel removeFromSuperview];
                             self.toolPannel=nil;
                             [self.markView removeFromSuperview];
                             self.markView=nil;
                             self.fontButton.enabled=YES;
                             self.isPannelShow=NO;
                             self.fontSizeButtons=nil;
                             
                         }];
        
    }else{
       // ((CLNavigationController *)[self k_rootController]).panGesture.enabled = NO;
        
        self.fontButton.enabled=NO;
        
        self.toolPannel=[[UIView alloc] init];
        self.toolPannel.frame=CGRectMake(0.f,GlobleHeight, GlobleWidth, 85.f);
        self.toolPannel.userInteractionEnabled = YES;
        [[self k_currentController].view addSubview:self.toolPannel];
        
        self.toolPannel.backgroundColor=[UIColor clearColor];
        
        if(AtLeastIOS8){
            
            UIVisualEffectView *effectview=[[UIVisualEffectView alloc]
                                            initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
            
            effectview.frame=self.toolPannel.bounds;
            [self.toolPannel addSubview:effectview];
            
        }else{
            UIView *bg=[UIView new];
            bg.backgroundColor =RGB(236.f, 236.f, 236.f);
            bg.alpha=0.99;
            bg.frame=self.toolPannel.bounds;
            [self.toolPannel addSubview:bg];
            
        }
        
        

        
        self.markView=[[UIView alloc] initWithFrame:self.view.superview.bounds];
        self.markView.backgroundColor=[UIColor blackColor];
        self.markView.alpha=0;
        [self.view.superview insertSubview:self.markView belowSubview:self.view ];
        
        [UIView animateWithDuration:0.15f
                         animations:^{
                             self.toolPannel.top=self.view.top-self.toolPannel.height;
                             
//                             CGRect frame=self.view.frame;
//                             frame.origin.y=GlobleHeight-85.f-44.f;
//                             frame.size.height=85+44.f;
//                             self.view.frame=frame;
                             self.markView.alpha=0.2;
                         }
                         completion:^(BOOL finished) {
                             self.fontButton.enabled=YES;
                             self.isPannelShow=YES;
                             UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                                 action:@selector(tapMark)];
                             [self.markView addGestureRecognizer:tap];
                         }];
        
        
        
        //字号设置
        UIView *fontPannel=[[UIView alloc] init];
        fontPannel.frame=CGRectMake(0, 0.f, GlobleWidth, 74.f);
        
        
        UILabel *left=[[UILabel alloc] init];
        left.frame=CGRectMake(15.f, 12, 70.f, 12.f);
        left.font=[UIFont systemFontOfSize:12.f];
        left.textColor=RGB(0x56, 0x56, 0x5e);
        
        left.text=@"字号设置";
        [fontPannel addSubview:left];
        [self.toolPannel addSubview:fontPannel];
        
        _fontPointImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 18, 18)];
        [_fontPointImg setImage:[UIImage imageNamed:@"setting_fontPoint_icon.png"]];
        _fontPointImg.backgroundColor = [UIColor clearColor];
        
        UIImageView *smallA = [[UIImageView alloc]initWithFrame:CGRectMake(14, 39, 10, 10)];
        smallA.backgroundColor = [UIColor clearColor];
        [smallA setImage:[UIImage imageNamed:@"set_font_smallA.png"]];
        smallA.userInteractionEnabled=YES;
        [self.toolPannel addSubview:smallA];
        
        UIImageView *bigA = [[UIImageView alloc]initWithFrame:CGRectMake(296, 34, 15, 15)];
        bigA.backgroundColor = [UIColor clearColor];
        [bigA setImage:[UIImage imageNamed:@"set_font_bigA.png"]];
        bigA.userInteractionEnabled=YES;
        [self.toolPannel addSubview:bigA];
        
        
        UIImageView *imgView1 = [[UIImageView alloc]initWithFrame:CGRectMake(40, 43.5, 240, 5.5)];
        imgView1.userInteractionEnabled = YES;
        [imgView1 setImage:[UIImage imageNamed:@"set_font_BG.png"]];
        [self.toolPannel addSubview:imgView1];
        
        
        self.fontSlider = [[UISlider alloc]initWithFrame:CGRectMake(31, 28.5, 240+12+6, 40.f)];
        self.fontSlider.layer.backgroundColor = [UIColor whiteColor].CGColor;
        self.fontSlider.userInteractionEnabled = YES;
        self.fontSlider.backgroundColor = [UIColor clearColor];
        self.fontSlider.minimumTrackTintColor = [UIColor clearColor];
        self.fontSlider.maximumTrackTintColor = [UIColor clearColor];
    

        if(1==([INHtmlElementUtil sharedInstance].level)){
            self.fontSlider.value = 0.f;
        }else if(2==([INHtmlElementUtil sharedInstance].level)){
            self.fontSlider.value = 80.f/258.f;;
        }else if(3==([INHtmlElementUtil sharedInstance].level)){
            self.fontSlider.value = 169.f/258.f;;
        }else if(4==([INHtmlElementUtil sharedInstance].level)){
            self.fontSlider.value = 0.99f;
        }
        
//        CGRect aframe=[self.toolPannel convertRect:self.fontSlider.frame toView:[self k_mainWindow]];
//        self.toolPannel.frame=aframe;
        [self.toolPannel addSubview:self.fontSlider];
        
//        UISlider *sle=[[UISlider alloc] initWithFrame:CGRectMake(0, 50, GlobleWidth, 1.f)];
//        [[self k_currentController].view addSubview:sle];
        
        UIImage *image = [UIImage imageNamed:@"setting_fontPoint_icon.png"];
        [self.fontSlider setThumbImage:image forState:UIControlStateNormal];
        
        [self.fontSlider setThumbImage:image forState:UIControlStateHighlighted];
        
        
        //滑块拖动时的事件
        [self.fontSlider addTarget:self action:@selector(sliderValueChanged) forControlEvents:UIControlEventValueChanged];
        //滑动拖动后的事件
        [self.fontSlider addTarget:self action:@selector(sliderDragUp) forControlEvents:UIControlEventTouchUpInside];
        
        

        
        
        UIButton *fontBtn1 = [[UIButton alloc]initWithFrame:CGRectMake(31, 40, 18, 18)];
        fontBtn1.backgroundColor = [UIColor clearColor];
        fontBtn1.tag = 151;
        [fontBtn1 addTarget:self action:@selector(choseFont:) forControlEvents:UIControlEventTouchUpInside];
//        [self.toolPannel addSubview:fontBtn1];
        
        UIButton *fontBtn2 = [[UIButton alloc]initWithFrame:CGRectMake(31+(1*80), 40, 18, 18)];
        fontBtn2.backgroundColor = [UIColor clearColor];
        fontBtn2.tag = 152;
        [fontBtn2 addTarget:self action:@selector(choseFont:) forControlEvents:UIControlEventTouchUpInside];
//        [self.toolPannel addSubview:fontBtn2];
        
        UIButton *fontBtn3 = [[UIButton alloc]initWithFrame:CGRectMake(31+(2*80), 40, 18, 18)];
        fontBtn3.backgroundColor = [UIColor clearColor];
        fontBtn3.tag = 153;
        [fontBtn3 addTarget:self action:@selector(choseFont:) forControlEvents:UIControlEventTouchUpInside];
//        [self.toolPannel addSubview:fontBtn3];
        
        UIButton *fontBtn4 = [[UIButton alloc]initWithFrame:CGRectMake(31+(3*80), 40, 18, 18)];
        fontBtn4.backgroundColor = [UIColor clearColor];
        fontBtn4.tag = 154;
        [fontBtn4 addTarget:self action:@selector(choseFont:) forControlEvents:UIControlEventTouchUpInside];
//        [self.toolPannel addSubview:fontBtn4];
        
//        if(1==([INHtmlElementUtil sharedInstance].level)){
//            [fontBtn1 addSubview:self.fontPointImg];
//        }else if(2==([INHtmlElementUtil sharedInstance].level)){
//            [fontBtn2 addSubview:self.fontPointImg];
//        }else if(3==([INHtmlElementUtil sharedInstance].level)){
//            [fontBtn3 addSubview:self.fontPointImg];
//        }else if(4==([INHtmlElementUtil sharedInstance].level)){
//            [fontBtn4 addSubview:self.fontPointImg];
//        }
        
        //音频
        if (_isYinpin) {
            self.backButton.hidden = YES;
            self.fontButton.hidden = YES;
            self.fontButton.frame = CGRectMake(0, 0, 0, 0);
            self.writeCommentButton.frame = CGRectMake(12.5, 8, 175, 28);
            self.showCommentButton.left=208.f;
        }
        
        
        /*UIView *buttonsView=[[UIView alloc] init];
        buttonsView.tag=50;
        buttonsView.frame=CGRectMake(95.f, 30.f, 200.f, 30.f);
        UIImageView *bg=[[UIImageView alloc] initWithFrame:buttonsView.bounds];
        bg.image=[UIImage imageNamed:@"tb_fontbg.png"];
        
        [buttonsView addSubview:bg];
        
        [self.toolPannel addSubview:buttonsView];
        
        
        int x=[INHtmlElementUtil sharedInstance].level;
        UIImageView *selected=[[UIImageView alloc] initWithFrame:CGRectMake((x-1)*50, 0, 50.f, 30.f)];
        selected.tag=100;
        selected.image=[UIImage imageNamed:@"tb_fontsize.png"];
        
        
        [buttonsView addSubview:selected];
        
        self.fontSizeButtons=[NSMutableArray arrayWithCapacity:4];
        
        __weak typeof(self) me=self;
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(0.f, 0.f, 50.f, 30.f);
        [button setTitle:@"小" forState:UIControlStateNormal];
        button.titleLabel.font=[UIFont systemFontOfSize:13];
        button.tag=101;
        [button setTitleColor:RGB(0x4d, 0x4d, 0x4d) forState:UIControlStateNormal];
        
        [buttonsView addSubview:button];
        [self.fontSizeButtons addObject:button];
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            if(me.fontblock){
                me.fontblock(0);
            }
        }];
        
        button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(50.f, 0.f, 50.f, 30.f);
        [button setTitle:@"中" forState:UIControlStateNormal];
        button.tag=102;
        button.titleLabel.font=[UIFont systemFontOfSize:13];
        [button setTitleColor:RGB(0x4d, 0x4d, 0x4d) forState:UIControlStateNormal];
        
        [buttonsView addSubview:button];
        [self.fontSizeButtons addObject:button];
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            if(me.fontblock){
                me.fontblock(1);
            }
        }];
        
        button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(100.f, 0.f, 50.f, 30.f);
        [button setTitle:@"大" forState:UIControlStateNormal];
        button.tag=103;
        button.titleLabel.font=[UIFont systemFontOfSize:13];
        [button setTitleColor:RGB(0x4d, 0x4d, 0x4d) forState:UIControlStateNormal];
        
        [buttonsView addSubview:button];
        [self.fontSizeButtons addObject:button];
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            if(me.fontblock){
                me.fontblock(2);
            }
        }];
        
        button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(150.f, 0.f, 50.f, 30.f);
        [button setTitle:@"特大" forState:UIControlStateNormal];
        button.tag=104;
        button.titleLabel.font=[UIFont systemFontOfSize:13];
        [button setTitleColor:RGB(0x4d, 0x4d, 0x4d) forState:UIControlStateNormal];
        
        [buttonsView addSubview:button];
        [self.fontSizeButtons addObject:button];
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            if(me.fontblock){
                me.fontblock(3);
            }
        }];*/
        
        
    }
}

-(void)sliderDragUp{
    
    NSLog(@"sliderDragUp");
    int font = 0;
    CGFloat sliderValue = self.fontSlider.value*258.f;
    if (sliderValue>=0.f && sliderValue<49.f) {
        [INHtmlElementUtil sharedInstance].level=1;
        [[INHtmlElementUtil sharedInstance] buidFont];
        self.fontSlider.value = 0.f;
        font = 0;
        
    }else if (sliderValue>=49.f && sliderValue<129.f) {
        [INHtmlElementUtil sharedInstance].level=2;
        [[INHtmlElementUtil sharedInstance] buidFont];
        self.fontSlider.value = 80.f/258.f;
        font = 1;
        
    }else if (sliderValue>=129.f && sliderValue<209.f) {
        [INHtmlElementUtil sharedInstance].level=3;
        [[INHtmlElementUtil sharedInstance] buidFont];
        self.fontSlider.value = 169.f/258.f;
        font = 2;
        
    }else if (sliderValue>=209.f && sliderValue<=258.f) {
        [INHtmlElementUtil sharedInstance].level=4;
        [[INHtmlElementUtil sharedInstance] buidFont];
        self.fontSlider.value = 0.99f;
        font = 3;
        
    }
    if(self.fontblock){
        self.fontblock(font);
    }
}

-(void)sliderValueChanged{
    
    NSLog(@"sliderValueChanged");
    
    
}

- (void) choseFont:(UIButton *)button {
    switch (button.tag) {
        case 151:
            [INHtmlElementUtil sharedInstance].level=1;
            [[INHtmlElementUtil sharedInstance] buidFont];
            [_fontPointImg removeFromSuperview];
            [button addSubview:_fontPointImg];
            break;
        case 152:
            [INHtmlElementUtil sharedInstance].level=2;
            [[INHtmlElementUtil sharedInstance] buidFont];
            [_fontPointImg removeFromSuperview];
            [button addSubview:_fontPointImg];
            break;
        case 153:
            [INHtmlElementUtil sharedInstance].level=3;
            [[INHtmlElementUtil sharedInstance] buidFont];
            [_fontPointImg removeFromSuperview];
            [button addSubview:_fontPointImg];
            break;
        case 154:
            [INHtmlElementUtil sharedInstance].level=4;
            [[INHtmlElementUtil sharedInstance] buidFont];
            [_fontPointImg removeFromSuperview];
            [button addSubview:_fontPointImg];
            break;
            
        default:
            break;
    }
    
    if(self.fontblock){
        self.fontblock(button.tag-151);
    }
}

- (void)showMorePannel:(int)setting{
    if(self.isPannelShow){
        self.fontButton.enabled=NO;
       //
        
        [UIView animateWithDuration:0.15f
                         animations:^{
                             CGRect frame=self.view.frame;
                             frame.origin.y=GlobleHeight-44.f;//170.f;
                             frame.size.height=44.f;
                             self.view.frame=frame;
                             self.markView.alpha=0;
                         }
                         completion:^(BOOL finished) {
                         //  ((CLNavigationController *)[self k_rootController]).panGesture.enabled = YES;
                             [self.toolPannel removeFromSuperview];
                             self.toolPannel=nil;
                             [self.markView removeFromSuperview];
                             self.markView=nil;
                             self.fontButton.enabled=YES;
                             self.isPannelShow=NO;
                             self.fontSizeButtons=nil;
                             
                         }];

    }else{
        self.fontButton.enabled=NO;
        
        self.toolPannel=[[UIView alloc] init];
        self.toolPannel.frame=CGRectMake(0.f, 44.f, GlobleWidth, 85.f);
        [self.view addSubview:self.toolPannel];
        
        if(AtLeastIOS8){
            
            UIVisualEffectView *effectview=[[UIVisualEffectView alloc]
                                            initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
            
            effectview.frame=self.toolPannel.bounds;
            [self.toolPannel addSubview:effectview];
            
        }else{
            UIView *bg=[UIView new];
            bg.backgroundColor =RGB(236.f, 236.f, 236.f);
            bg.alpha=0.99;
            bg.frame=self.toolPannel.bounds;
            [self.toolPannel addSubview:bg];
            
        }
        
        self.markView=[[UIView alloc] initWithFrame:self.view.superview.bounds];
        self.markView.backgroundColor=[UIColor blackColor];
        self.markView.alpha=0;
        [self.view.superview insertSubview:self.markView belowSubview:self.view ];
        
        [UIView animateWithDuration:0.15f
                         animations:^{
                             CGRect frame=self.view.frame;
                             frame.origin.y=GlobleHeight-85.f-44.f;
                             frame.size.height=85+44.f;
                             self.view.frame=frame;
                             self.markView.alpha=0.2;
                         }
                         completion:^(BOOL finished) {
                             self.fontButton.enabled=YES;
                             self.isPannelShow=YES;
                             UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                                 action:@selector(tapMark)];
                             [self.markView addGestureRecognizer:tap];
                         }];
        
   
        
        //字号设置
        UIView *fontPannel=[[UIView alloc] init];
        fontPannel.frame=CGRectMake(0, 30.f, GlobleWidth, 30.f);
        
        
        UILabel *left=[[UILabel alloc] init];
        left.frame=CGRectMake(21.f, 0, 70.f, 28.f);
        left.font=[UIFont systemFontOfSize:14.f];
        left.textColor=RGB(0x4d, 0x4d, 0x4d);
     
        left.text=@"字号设置";
        [fontPannel addSubview:left];
        [self.toolPannel addSubview:fontPannel];
        
        UIView *buttonsView=[[UIView alloc] init];
        buttonsView.tag=50;
        buttonsView.frame=CGRectMake(95.f, 30.f, 200.f, 30.f);
        UIImageView *bg=[[UIImageView alloc] initWithFrame:buttonsView.bounds];
        bg.image=[UIImage imageNamed:@"tb_fontbg.png"];
      
        [buttonsView addSubview:bg];
        
        [self.toolPannel addSubview:buttonsView];
        
        
        int x=[INHtmlElementUtil sharedInstance].level;
        UIImageView *selected=[[UIImageView alloc] initWithFrame:CGRectMake((x-1)*50, 0, 50.f, 30.f)];
        selected.tag=100;
        selected.image=[UIImage imageNamed:@"tb_fontsize.png"];
      
        
        [buttonsView addSubview:selected];
        
        self.fontSizeButtons=[NSMutableArray arrayWithCapacity:4];
        
        __weak typeof(self) me=self;
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(0.f, 0.f, 50.f, 30.f);
        [button setTitle:@"小" forState:UIControlStateNormal];
        button.titleLabel.font=[UIFont systemFontOfSize:13];
        button.tag=101;
        [button setTitleColor:RGB(0x4d, 0x4d, 0x4d) forState:UIControlStateNormal];
   
        [buttonsView addSubview:button];
        [self.fontSizeButtons addObject:button];
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            if(me.fontblock){
                me.fontblock(0);
            }
        }];
        
        button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(50.f, 0.f, 50.f, 30.f);
        [button setTitle:@"中" forState:UIControlStateNormal];
        button.tag=102;
        button.titleLabel.font=[UIFont systemFontOfSize:13];
        [button setTitleColor:RGB(0x4d, 0x4d, 0x4d) forState:UIControlStateNormal];
    
        [buttonsView addSubview:button];
        [self.fontSizeButtons addObject:button];
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            if(me.fontblock){
                me.fontblock(1);
            }
        }];
        
        button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(100.f, 0.f, 50.f, 30.f);
        [button setTitle:@"大" forState:UIControlStateNormal];
        button.tag=103;
        button.titleLabel.font=[UIFont systemFontOfSize:13];
        [button setTitleColor:RGB(0x4d, 0x4d, 0x4d) forState:UIControlStateNormal];
 
        [buttonsView addSubview:button];
        [self.fontSizeButtons addObject:button];
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            if(me.fontblock){
                me.fontblock(2);
            }
        }];
        
        button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(150.f, 0.f, 50.f, 30.f);
        [button setTitle:@"特大" forState:UIControlStateNormal];
        button.tag=104;
        button.titleLabel.font=[UIFont systemFontOfSize:13];
        [button setTitleColor:RGB(0x4d, 0x4d, 0x4d) forState:UIControlStateNormal];
    
        [buttonsView addSubview:button];
        [self.fontSizeButtons addObject:button];
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            if(me.fontblock){
                me.fontblock(3);
            }
        }];


    }
}

- (void)addListnerFont:(void(^)(int index))block{
    self.fontblock=block;
}

- (void)resizeComment{
    __weak typeof(self)pself=self;
    CGRect aframe=self.showCommentButton.frame;
    
    if(pself.commentBg){
        [pself.commentBg removeFromSuperview];
        pself.commentBg=nil;
    }
    pself.commentBg=[UIView new];
    pself.commentBg.frame=pself.showCommentButton.bounds;
    pself.commentBg.userInteractionEnabled=NO;
    [pself.showCommentButton addSubview:pself.commentBg];
    
    CGRect tframe=self.showCommentButton.frame;
    
    UIImageView *frontView = [[UIImageView alloc]
                              initWithImage:
                              [UIImage imageNamed:self.isSlider?@"slider_comment_left.png":@"tb_comment_left.png"]];
    
    frontView.frame = CGRectMake(0, 3, 11.5, 20);
    [pself.commentBg addSubview:frontView];
    
    UIImageView *middleView = [[UIImageView alloc] initWithImage:
                               [UIImage imageNamed:self.isSlider?@"slider_comment_middle.png":@"tb_comment_middle.png"]];
    middleView.frame = CGRectMake(11.5, 3, aframe.size.width-4-13, 20);
    [pself.commentBg addSubview:middleView];
    
    UIImageView *backView = [[UIImageView alloc] initWithImage:
                             [UIImage imageNamed:self.isSlider?@"slider_comment_right.png":@"tb_comment_right.png"]];
    backView.frame = CGRectMake(tframe.size.width-8, 3, 8, 20);
    [pself.commentBg addSubview:backView];
}

- (void)update:(int)commentCount{
    NSString *str=nil;
    if(commentCount<=0){
      //  self.showCommentButton.hidden=YES;
        CGRect frame = self.writeCommentButton.frame;
        frame.size.width = self.showCommentButton.right-frame.origin.x;
     //   self.writeCommentButton.frame = frame;
   
        return;
    }else if(commentCount>9999){
        int n=commentCount/1000;
        str=[NSString stringWithFormat:@"%.1f万",((float)n/10.f)];
    }else{
        str=[NSString stringWithFormat:@"%d",commentCount];
    }
    
    CGRect aframe = self.writeCommentButton.frame;
    aframe.size.width = self.showCommentButton.left-40-20;
   // self.writeCommentButton.frame = aframe;
    
    self.showCommentButton.hidden=NO;

    CGSize size=[str sizeWithFont:self.countLabel.font];
    CGRect frame=self.showCommentButton.frame;
    
    if(size.width>15.f){
        frame.origin.x-= fabsf((size.width+10.f)-frame.size.width);
        frame.size.width=size.width+10.f;
        self.showCommentButton.frame=frame;
    }else{
        frame.size.width=22.f;
        frame.origin.x=0.f;
    }
    
    
    [self resizeComment];
    frame=self.showCommentButton.bounds;
    frame.size.height=15.f;
    frame.origin.y=3.f;
   // frame.size.width-=frame.size.width-4.f;
    self.countLabel.frame=frame;
    
    self.countLabel.text=str;
    
}




- (void)handleTap:(IFActive_ButtomToolBarButtonType )type block:(void(^)(id sender))block{
    switch (type) {
        case IFActive_ButtomToolBarButtonTypeWriteComment:
            [self.writeCommentButton handleControlEvent:UIControlEventTouchUpInside
                                              withBlock:block];
            break;
            
        case IFActive_ButtomToolBarButtonTypeShowComment:
            [self.showCommentButton handleControlEvent:UIControlEventTouchUpInside withBlock:block];
            break;
            
        case IFActive_ButtomToolBarButtonTypeShare:
            [self.shareButton handleControlEvent:UIControlEventTouchUpInside withBlock:block];
            break;
        case IFActive_ButtomToolBarButtonTypeDownloadImg:
            [self.download handleControlEvent:UIControlEventTouchUpInside withBlock:block];
                default:
            break;
    }
}

- (void)addListnerMore:(void(^)(BOOL isshow))block{
    self.more=block;
}

- (void)setCollectId:(NSString *)collectId{
    _collectId=collectId;
    __weak typeof(self)me=self;
    [[CLCollectModel sharedInstance] checkExitByItemId:collectId block:^(BOOL success) {
        [me setIsCollected:success];
    }];
}

- (void)setIsCollected:(BOOL)isCollected{
    _isCollected=isCollected;
    if(isCollected){
         [self.litCollectButton setImage:[UIImage imageNamed:@"tb_collected.png"] forState:UIControlStateNormal];
    }else{
        [self.litCollectButton setImage:[UIImage imageNamed:self.isSlider?@"slider_collect_icon.png":@"tb_collect.png"] forState:UIControlStateNormal];
    }
}




- (void)activeFontSize:(int)tag{
    
    if(!self.toolPannel) return;
    UIView *view=[self.toolPannel viewWithTag:100];
    for(int i=1;i<5;i++){
        UIButton *button=(UIButton *)[self.toolPannel viewWithTag:100+i];
        button.selected=NO;
    }
    
    UIButton *button=(UIButton *)[self.toolPannel viewWithTag:100+tag+1];
    button.selected=YES;

    
    [UIView animateWithDuration:0.1
                     animations:^{
                         view.frame=CGRectMake(50.f*tag, 0, 50.f, 30.f);
                     }];
    
}




- (void)setCollocId:(NSString *)collocId andData:(NSDictionary *)data pty:(NSString *)pty{
    
}










@end
